package com.zhanqiao.Dao;

import com.zhanqiao.Utils.GetDataSourceUtil;
import com.zhanqiao.domain.ArticleBean;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;

public class SelectStatedContentDao implements ArticleDao {
    @Override
    public int insertArticle(ArticleBean articleBean) {
        return 0;
    }

    @Override
    public int deleteArticle(int articleId) {
        return 0;
    }

    @Override
    public List<ArticleBean> selectAll() {
        return null;
    }

    @Override
    public int updateArticle(int id, Date publishdate, String title, String content) {
        return 0;
    }
    public List<ArticleBean> selectAll(String page,String limit) {
        DataSource ds = GetDataSourceUtil.getDataSource();
        QueryRunner queryRunner = new QueryRunner(ds);
        int pages = Integer.parseInt(page);
        int counts = Integer.parseInt(limit);
        Object[] parm = {(pages-1)*counts,counts};
        String sql = "select * from article where sendstate=0 limit ?,?";
        try {
            List<ArticleBean> allArticles = queryRunner.query(sql, new BeanListHandler<ArticleBean>(ArticleBean.class),parm);
            return allArticles;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
